// 得到现在的时间
export const getNowDates = (d?: Date) => {
  let date = d || new Date()
  let year = date.getFullYear()
  let month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
  let day = date.getDate() < 10 ? '0'+ date.getDate() : date.getDate()

  return `${year}-${month}-${day}`
}

// 得到现在的时间 时分秒
export const getNowDateHMS = (d?: Date) => {
  let date = d || new Date()
  let year = date.getFullYear()
  let month = date.getMonth() + 1
  let day = date.getDate() < 10 ? '0'+ date.getDate() : date.getDate()

  return `${year}-${month}-${day} 00:00:00`
}

// 得到现在的时间
export const getNowDate = (d?: Date) => {
  let date = d || new Date()
  let year = date.getFullYear()
  let month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
  let day = date.getDate() < 10 ? '0'+ date.getDate() : date.getDate()
  let HH = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
  let mm = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
  let ss = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()

  return `${year}-${month}-${day} ${HH}:${mm}:${ss}`
}

// 得到明天的时间
export const getOldDate = (d?: Date) => {
  let date = d || new Date()
  let year = date.getFullYear()
  let month = date.getMonth() + 1
  let day = date.getDate() + 1

  return `${year}-${month}-${day} 00:00:00`
}

export const getMonth = (d?: Date) => {
  let date = d || new Date()
  let year = date.getFullYear()
  let month = date.getMonth() + 1


  return `${year}-${month}`
}

export const getCurrentMonthlastDay = (d?: Date) => {
  let date = d || new Date()
  let year = date.getFullYear()
  let month = date.getMonth() + 1
  let lastDay = new Date(year, month, 0).getDate()
  
  return `${year}-${month}-${lastDay}`;
}


export const setDate = (timeNum: number, time: string) => {
  let times: any;
  if(time === '天') {
   times =  timeNum * 1 * 60 * 60 * 24 * 1000
  } else if (time === '周') {
    times =  timeNum * 7 * 60 * 60 * 24 * 1000
  } else if(time === '月') {
    times =  timeNum * 30 * 60 * 60 * 24 * 1000
  }

  
  let data = new Date(new Date().getTime() + times)
  let y = data.getFullYear()
  let m = data.getMonth() + 1  < 10 ? '0' + (data.getMonth() + 1) : data.getMonth() + 1
  let d = data.getDate() < 10 ? '0'+ data.getDate() : data.getDate()
  
  return `${y}-${m}-${d}`
}